﻿using System;

namespace MessagePack.Formatters
{
	// Token: 0x02000039 RID: 57
	public class UInt16ArrayFormatter : IMessagePackFormatter<ushort[]>
	{
		// Token: 0x060000D3 RID: 211 RVA: 0x000042D5 File Offset: 0x000026D5
		private UInt16ArrayFormatter()
		{
		}

		// Token: 0x060000D4 RID: 212 RVA: 0x000042E0 File Offset: 0x000026E0
		public int Serialize(ref byte[] bytes, int offset, ushort[] value, IFormatterResolver formatterResolver)
		{
			if (value == null)
			{
				return MessagePackBinary.WriteNil(ref bytes, offset);
			}
			int num = offset;
			offset += MessagePackBinary.WriteArrayHeader(ref bytes, offset, value.Length);
			for (int i = 0; i < value.Length; i++)
			{
				offset += MessagePackBinary.WriteUInt16(ref bytes, offset, value[i]);
			}
			return offset - num;
		}

		// Token: 0x060000D5 RID: 213 RVA: 0x00004330 File Offset: 0x00002730
		public ushort[] Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
		{
			if (MessagePackBinary.IsNil(bytes, offset))
			{
				readSize = 1;
				return null;
			}
			int num = offset;
			int num2 = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
			offset += readSize;
			ushort[] array = new ushort[num2];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = MessagePackBinary.ReadUInt16(bytes, offset, out readSize);
				offset += readSize;
			}
			readSize = offset - num;
			return array;
		}

		// Token: 0x0400002D RID: 45
		public static readonly UInt16ArrayFormatter Instance = new UInt16ArrayFormatter();
	}
}
